home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
answers
/
news
/
perl-faq
/
part2
< prev
next >
Wrap
Text File
|
1993-10-01
|
24KB
|
612 lines
Newsgroups: comp.lang.perl,news.answers
Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!spool.mu.edu!agate!boulder!wraeththu.cs.colorado.edu!tchrist
From: Tom Christiansen <tchrist@cs.Colorado.EDU>
Subject: Perl Frequently Asked Questions, part 2 of 4
Message-ID: <CE9BqE.25o@Colorado.EDU>
Followup-To: comp.lang.perl
Originator: tchrist@wraeththu.cs.colorado.edu
Sender: news@Colorado.EDU (USENET News System)
Organization: University of Colorado at Boulder
Date: Sat, 2 Oct 1993 06:37:26 GMT
Approved: news-answers-request@MIT.Edu
Expires: Wed, 1 Dec 1993 12:00:00 GMT
Lines: 596
Xref: senator-bedfellow.mit.edu comp.lang.perl:20583 news.answers:13121
Archive-name: perl-faq/part2
Version: $Id: perl-info2,v 1.1 93/10/02 00:27:07 tchrist Exp Locker: tchrist $
This posting contains answers to general information questions,
mostly of a non-technical nature. The following questions are
answered in this posting:
1.21) Is there a Perl profiler?
1.22) Is there a yacc for Perl?
1.23) How can I use curses with perl?
1.24) How can I use X with Perl?
1.25) What is perl4? What is perl5?
1.26) How does Perl compare with languages like REXX or TCL?
1.27) Is it a Perl program or a Perl script?
1.28) What's the difference between "Perl" and "perl"?
1.29) What companies use or ship Perl?
1.30) Is there commercial, 3rd-party support for Perl?
1.31) Where can I get a list of the JAPH signature quotes?
1.32) Where can I get a list of Larry Wall witticisms?
1.33) Is there a pretty-printer for Perl?
1.34) Can I dynamically load C user routines?
1.21) Is there a Perl profiler?
While there isn't one included with the perl source distribution (yet)
various folks have written packages that allow you to do at least some
sort of profiling. The strategy usually includes modifying the perl
debugger to handle profiling. Authors of these packages include
Wayne Thompson <me@anywhere.EBay.Sun.COM>
Ray Lischner <lisch@sysserver1.mentor.com>
Kresten Krab Thorup <krab@iesd.auc.dk>
The original articles by these folks containing their
profilers are available on convex.com in
/pub/perl/information/profiling.shar via anon ftp.
1.22) Is there a yacc for Perl?
Yes!! It's a version of Berkeley yacc that outputs Perl code instead
of C code! You can get this from ftp.sterling.com [192.124.9.1] in
/local/perl-byacc1.8.1.tar.Z, or send the author mail for details.
1.23) How can I use curses with perl?
One way is to build a curseperl binary by linking in your C curses
library as described in the usub subdirectory of the perl sources.
This requires a modicum of work, but it will be reasonably fast
since it's all in C (assuming you consider curses reasonably fast. :-)
Programs written using this method require the modified curseperl,
not vanilla perl, to run. While this is something of a disadvantage,
experience indicates that it's better to use curseperl than to
try to roll your own using termcap directly.
For a good example of using curseperl, you might want to pick up a
copy of Steven L Kunz's <skunz@iastate.edu> "perl menus" package
("menu.pl") via anonymous FTP from "ftp.iastate.edu". It's in the
/pub/perl as
menu.pl.v1.4.shar
menu.pl.v2.0.shr1
menu.pl.v2.0.shr2
menu.pl.v2.0.tar.Z
menus.pl is a complete menu front-end for curseperl and demonstates
a lot of things (plus it is useful to boot if you want full-screen
menu selection ability).
Another possibility is to use Henk Penning's cterm package, a curses
emulation library written in perl. cterm is actually a separate
program with which you communicate via a pipe. It is available from
ftp.cs.ruu.nl [131.211.80.17] via anonymous ftp. in the directory
pub/PERL. You may also acquire the package via email in compressed,
uuencoded form by sending a message to mail-server@cs.ruu.nl
containing these lines:
begin
send PERL/cterm.shar.Z
end
See the question on retrieving perl via mail for more information on
how to get retrieve other items of interest from the mail server
there.
1.24) How can I use X with Perl?
Right now, you have several choices. You can wait for perl5, use
the WAFE or STDWIN packages, or try to make your own usub bindings.
Perl5 is anticipated to be released with bindings for X, called
guiperl. An exciting prototype for this, written by Jon Biggar
<jon@netlabs.com>, Larry's *other* brother-in-law and officemate,
is already up and running inside of Netlabs. This program addresses
the same dynamic gui-building problem space as does tcl/tk.
If you can't wait or don't think that guiperl will do what you want,
a stab at Motif bindings was begun by Theodore C. Law
<TEDLAW@TOROLAB6.VNET.IBM.COM> area. His article about this is
on convex.com in /pub/perl/info/motif for anon ftp.
STDWIN is a library written by Guido van Rossum <guido@cwi.nl>
(author of the Python programming language) that is portable
between Mac, Dos and X11. One could write a Perl agent to
speak to this STDWIN server.
WAFE is a package that implements a symbolic interface to the Athena
widgets (X11R5). A typical Wafe application consists in our framework
of two parts: the front-end (we call it Wafe for Widget[Athena]front
end) and an application program running typically as separate process.
The application program can be implemented in an arbitrary programming
language and talks to the front-end via stdio. Since Wafe (the
front-end) was developed using the extensible TCL shell (cite John
Ousterhout), an application program can dynamically submit requests to
the front-end to build up the graphical user interface; the
application can even down-load application specific procedures into
the front-end. The distribution contains sample application programs
in Perl, GAWK, Prolog, TCL, and C talking to the same Wafe binary.
Many of the demo applications are implemented in Perl. Wafe 0.9 can
be obtained via anonymous ftp from
ftp.wu-wien.ac.at:pub/src/X11/wafe-0.9.tar.Z
(for people without name server: the ip address is 137.208.3.5)
Alternatively, you could use wish from tcl.
#!/usr/local/bin/perl
#####################################################################
# An example of calling wish as a subshell under Perl and
# interactively communicating with it through sockets.
#
# The script is directly based on Gustaf Neumann's perlwafe script.
#
# Dov Grobgeld dov@menora.weizmann.ac.il
# 1993-05-17
#####################################################################
$wishbin = "/usr/local/bin/wish";
die "socketpair unsuccessful: $!!\n" unless socketpair(W0,WISH,1,1,0);
if ($pid=fork) {
select(WISH); $| = 1;
select(STDOUT);
# Create some TCL procedures
print WISH 'proc echo {s} {puts stdout $s; flush stdout}',"\n";
# Create the widgets
print WISH <<TCL;
# This is a comment "inside" wish
frame .f -relief raised -border 1 -bg green
pack append . .f {top fill expand}
button .f.button-pressme -text "Press me" -command {
echo "That's nice."
}
button .f.button-quit -text quit -command {
echo "quit"
}
pack append .f .f.button-pressme {top fill expand} \\
.f.button-quit {top expand}
TCL
;
# Here is the main loop which receives and sends commands
# to wish.
while (<WISH>) {
chop;
print "Wish sais: <$_>\n";
if (/^quit/) { print WISH "destroy .\n"; last; }
}
wait;
} elsif (defined $pid) {
open(STDOUT, ">&W0");
open(STDIN, ">&W0");
close(W0);
select(STDOUT); $| = 1;
exec "$wishbin --";
} else {
die "fork error: $!\n";
}
1.25) What is perl4? What is perl5?
The answer to what is perl4 is nearly anything you might otherwise
program in shell or C. The answer to what is perl5 is basically
Perl: the Next Generation. In fact, it's essentially a complete
rewrite of perl from the bottom up, and back again. It's available
in alpha form (alpha-2 now, alpha-3 soon). The only docs for this stuff
is what you're about to read, and what's in the t/op/ref.t file.
Here are the things which are already done:
a faster, tighter, more flexible interpreter
new token "=>" as synonym for ","; this makes
tables look nicer
%T = ( OC => $red,
TOF => "\f",
);
and provides for named argument passing:
&some_func( OC => $red, TOF => "\f");
recursive lists and tables:
[a, b, [c, d], e] has 4 elts, the 3rd being itself a list
$r->[3]->{PEANUT}; $r is a reference to a list
of references to tables
typed pointers (references) and generalized indirection:
like @{$aptr} or &{$fptr} or &{ $table[$index] . "func" }().
merging of list operator and function calling syntax:
split /pat/, $string;
the ref operator to find out what something is a reference to
object oriented programming:
$o->func(); # call the func member function of whatever class $o is
inheritance of object types through the @ISA array
much improved -w checking
lexical scoping with the my operator
safe global variables through package statements
forces variable declarations, but only if you want it
per-package END functions triggered at die() or exit()
embeddable Perl code in C code: cc prog.c -lperl
oo syntactic extensions:
$dog->give($bone);
is like
give $dog $bone;
and
$STDOUT->flush(1);
is like
flush $STDOUT 1;
multiple co-resident perl interpreters:
Here is what is hoped to be done for production, but might not:
very easy GUI Perl applications using high-level X bindings ("guiperl")
subroutines without &'s: myfunc($arg);
mnemonic aliases for $<punctuation> variables
file handle objects: $STDOUT->flush(1);
cleanup (namespace pollution) and documentation
(eg. man 3pl getopt) of libraries
addition of several new libraries (atexit, autoload, etc.)
update h2ph and c2ph
misc perl development tools
a perl profiler
POSIX compatibility
Here is what is hope to eventually be done but very probably not in
the first production release:
generalization of dbm binding for assoc arrays to handle
any generic fetch/store/open/close/flush package.
(thus allowing both dbm and gdbm at once)
dynamic loading of C libraries for systems that can
byte-compiled code for speed and maybe security
And here are the things that will no longer work that used to:
open FILE || die;
$c = shift @a + 1;
It's tempting to want this stuff soon, since the sooner it comes
out the sooner we can all build really cool applications. But the
longer Larry works on it, the more items from this list will actually
get done, and the more robust the release will be. So let's not
ask him about it too often. Larry says (slightly edited):
I've put a tar of my current Perl 5 directory onto
ftp.netlabs.com, in pub/outgoing/perl5.0/perl5a2.tar.Z.
Now's your chance to check out all the bugs I said I fixed in
Perl 5. :-)
Before you get all twitterpated, this is unsupported "alpha 2"
code. There is no Configure, only a makefile. It will
probably only work on a Sun4. The compiler and interpreter are
still very much unoptimized (though it already runs as fast or
faster than Perl 4). It doesn't do everything that I want it
to yet. It doesn't have "my" yet (though it's got the innards
for it). It doesn't have a debugger.
Like the Alpha 1 prerelease, this is an unsupported code. It is
expected to work only on a Sparc architecture machine. No
Configure support is provided. In fact, if you succeed in
configuring and making a new makefile, you'll probably overwrite
the only makefile that works. (Note that a Sparc executable comes
with the kit, so you may not need to compile at all.) There is
no list of new features yet, but if you look at t/op/ref.t
you'll see some of them in use. perl -Dxst is also fun.
But it does have references, and you can play with them. The
object oriented stuff is there too. See the op/ref.t file for
how to use them.
I smell some new JAPHs coming...
I don't want to get stuck "supporting" this, but if you want to
run your favorite scripts past it and see which ones toss their
salad, you may. If you can come up with a decent bug report
with a small test case, I'll certainly be glad to look at it.
I'm not really interested in obscure core dumps at the moment.
I'm still getting plenty of those on my own.
I'm not yet interested in memory leak reports either.
I can tell you that no program that uses the old autoloading
mechanism will run, since there is no visibility into the
symbol table pointers currently. You ought to be able to
redefine a subroutine while it's running, though. (I haven't
tested that in several months, however. There oughta be a
regression test for that...)
Don't bother trying to diff Perl 4 with Perl 5. Everything is
different. All names have been regularized. Here's a key, if
you're brave and want to peek at the sources:
SV scalar value
AV array value
HV hash value
GV glob value
CV code value
RV reference value
PV pointer value
NV numeric value
IV integer value
1.26) How does Perl compare with languages like REXX or TCL?
REXX is an interpreted programming language first seen on IBM systems,
and TCL is John Ousterhout's embeddable command language. TCL's most
intriguing feature for many people is the tcl/tk toolset that allows
for interpreted X-based tools.
To avoid any flamage, if you really want to know the answer to this
question, probably the best thing to do is try to write equivalent
code to do a set of tasks. All three have their own newsgroups in
which you can learn about (but hopefully not argue about) these
languages.
To find out more about these or other languages, you might also check
out David Muir Sharnoff <muir@tfs.com>'s posting on "Catalog of
compilers, interpreters, and other language tools" which he posts to
comp.lang.misc, comp.sources.d, comp.archives.admin, and the
news.answers newsgroups. It's a comprehensive treatment of many
different languages. (Caveat lector: he considers Perl's syntax
"unappealing".) This list is archived on convex.com in
/pub/perl/info/lang-survey.shar .
1.27) Is it a Perl program or a Perl script?
Certainly. :-)
Current UNIX parlance holds that anything interpreted
is a script, and anything compiled into native machine
code is a program. However, others hold that a program
is a program is a program: after all, one seldom discusses
scripts written in BASIC or LISP. Larry considers it
a program if it's set in stone and you can't change it,
whereas if you go in and hack on it, then it's a script.
But doesn't really matter. The terms are generally
interchangeable today.
1.28) What's the difference between "Perl" and "perl"?
32 :-) [ ord('p') - ord('P') ]
Larry now uses "Perl" to signify the language proper and "perl" the
implementation of it, i.e. the current interpreter. Hence tchrist's quip
that "Nothing but perl can parse Perl."
On the other hand, the aesthetic value of casewise parallelism
in "awk", "sed", and "perl" as much require the lower-case
version as "C", "Pascal", and "Perl" require the
upper-case version. It's also easier to type "Perl" in
typeset print than to be constantly switching in Courier. :-)
In other words, it doesn't matter much, especially if all
you're doing is hearing someone talk about the language;
case is hard to distinguish aurally.
1.29) What companies use or ship Perl?
At this time, the known list of companies that ship Perl includes at
least the following, although some have snuck it into /usr/contrib
or its moral equivalent:
BSDI
Comdisco Systems
CONVEX Computer Corporation
Crosspoint Solutions
Dell
DRD Corporation
Intergraph
Kubota Pacific
Netlabs
Univel
Furthermore, the following vendors are reported to begin shipping perl
standard with their systems in the very near future:
Sun
SGI
Some companies ship it on their "User Contributed Software Tape",
such as DEC and HP. Apple Computer has shipped the MPW version of
Macintosh Perl on one of their Developer CDs (Essentials*Tools*Objects
#11) (and they included it under "Essentials" :-)
Many other companies use Perl internally for purposes of tools
development, systems administration, installation scripts, and test
suites. Rumor has it that the large workstation vendors (the TLA set)
are seriously looking into shipping Perl with their standard systems
"soon".
People with support contracts with their vendors are actively
encouraged to submit enhancement requests that Perl be shipped
as part of their standard system. It would, at the very least,
reduce the FTP load on the Internet. :-)
If you know of any others, please send them in.
1.30) Is there commercial, 3rd-party support for Perl?
Not really. Although perl is included in the GNU distribution, at
last check, Cygnus does not offer support for it. However, it's
unclear whether they've ever been offered sufficient financial
incentive to do so.
On the other hand, you do have comp.lang.perl as a totally gratis
support mechanism. As long as you ask "interesting" questions,
you'll probably get plenty of help. :-)
While some vendors do ship Perl with their platforms, that doesn't
mean they support it on arbitrary other platforms. And in fact, all
they'll probably do is forward any bug reports on to Larry. In
practice, this is far better support than you could hope for from
nearly any vendor.
The companies who won't use something unless they can pay money
for it will be left out. Often they're motivated by wanting
someone whom they could sue. If all they want is someone to help
them out with Perl problems, there's always the net. And if they
really want to pay someone for that help, well, Tom and Randal are
always looking for a job. :-)
If companies want "commercial support" for it badly enough, speak
up -- something might be able to be arranged.
1.31) Where can I get a list of the JAPH signature quotes?
These are the "just another perl hacker" signatures that
some people sign their postings with. About 100 of the
of the earlier ones are on convex.com in /pub/perl/info/japh.
1.32) Where can I get a list of Larry Wall witticisms?
Over a hundred quips by Larry, from postings of his or source code,
can be found on convex.com in /pub/perl/info/lwall-quotes.
1.33) Is there a pretty-printer for Perl?
That depends on what you mean. If you want something
that works like vgrind on Perl programs, then the answer
is "yes, nearly". Here's a vgrind entry for perl:
PERL|perl|Perl:\
:pb=^\d?(sub|package)\d\p\d:\
:bb={:be=}:cb=#:ce=$:sb=":se=\e":lb=':\
:le=\e':tl:\
:id=_:\
:kw=\
if for foreach unless until while continue else elsif \
do eval require \
die exit \
defined delete reset \
goto last redo next dump \
local undef return \
write format \
sub package
It doesn't actually do everything right; in particular,
things like $#, $', s#/foo##, and $foo'bar all confuse it.
David Levine uses this:
# perl 4.x David Levine <levine@ics.uci.edu> 05 apr 1993
# Derived from Tom Christiansen's perl vgrindef. I'd like to treat all of
# perl's built-ins as keywords, but vgrind fields are limited to 1024
# characters and the built-ins overflow that (surprise :-). So, I didn't
# include the dbm*, end*, get*, msg*, sem*, set*, and shm* functions. I
# couldn't come up with an easy way to distinguish beginnings of literals
# ('...') from package prefixes, so literals are not marked.
# Be sure to:
# 1) include whitespace between a subprogram name and its opening {
# 2) include whitespace before a comment (so that $# doesn't get interpreted as
# one).
perl4:\
:pb=^\d?(sub|package)\d\p\d:\
:id=$%@_:\
:bb=\e{:be=\e}:cb=\d\e#:ce=$:sb=\e":se=\e":\
:kw=accept alarm atan2 bind binmode caller chdir chmod chop chown \
chroot close closedir connect continue cos crypt defined delete die do dump \
each else elsif eof eval exec exit exp fcntl fileno flock for foreach fork \
format getc gmtime goto grep hex if include index int ioctl join keys kill \
last length link listen local localtime log lstat m mkdir next oct open \
opendir ord pack package pipe pop print printf push q qq qx rand read readdir \
readlink recv redo rename require reset return reverse rewinddir rindex rmdir \
s scalar seek seekdir select send shift shutdown sin sleep socket socketpair \
sort splice split sprintf sqrt srand stat study sub substr symlink syscall \
sysread system syswrite tell telldir time times tr truncate umask undef \
unless unlink unpack unshift until utime values vec wait waitpid wantarray \
warn while write y:
If what you mean is whether there is a program that will
reformat the program much as indent(1) will do for C, then
the answer is no. The complex feedback between the scanner
and the parser (as in the things that confuse vgrind) make
it challenging at best to write a stand-alone C parser.
1.34) Can I dynamically load C user routines?
Yes, kinda. One package has been released that does this, by
Roberto Salama <rs@fi.gs.com>. He writes:
Here is a version of dylperl, dynamic linker for perl. The code here
is based on Oliver Sharp's May 1993 article in Dr. Dobbs Journal
(Dynamic Linking under Berkeley UNIX).
dyl.h
dyl.c - code extracted from Oliver Sharp's article
hash.h
hash.c - Berkeley's hash functions, should use perl's but could not
be bothered
dylperl.c - perl usersubs
user.c - userinit function
sample.c - sample code to be dyl'ed
sample2.c - "
test.pl - sample perl script that dyl's sample*.o
The Makefile assumes that uperl.o is in /usr/local/src/perl/... You
will probable have to change this to reflect your installation. Other
than that, just type 'make'...
The idea behind being able to dynamnically link code into perl is that
the linked code should become perl functions, i.e. they can be invoked
as &foo(...). For this to happen, the incrementally code must use the
perl stack, look at sample.c to get a better idea.
The few functions that make up this package are outlined below.
&dyl("file.o"): dynamically link file.o. All functions and non-static
variables become visible from within perl. This
function returns a pointer to an internal hash table
corresponding to the symbol table of the newly loaded
code.
eg: $ht = &dyl("sample.o")
This function can also be called with the -L and -l ld options.
eg: $ht = &dyl(""sample2.o", "-L/usr/lib", "-lm")
will also pick up the math library if sample.o
accesses any symbols there.
&dyl_find("func"): find symbol 'func' and return its symbol table entry
&dyl_functions($ht): print the contents of the internal hash table
&dyl_print_symbols($f): prints the contents of the symbol returned by dyl_find()
There is very little documentation, maybe something to do for a future
release. The files sample.o, and sample2.o contain code to be
incrementally loaded, test.pl is the test perl script.
Comments are welcome. I submit this code for public consumption and,
basically, am not responsible for it in any way.
--
Tom Christiansen tchrist@cs.colorado.edu
Consultant
Boulder Colorado 303-444-3212